<?php
require_once WACT_ROOT.'/db/db.inc.php';

if (defined("SPORTSITE_CLASS")) { print 'Site already defined'; return; }

if ( class_exists( "SportSite" ) )  { print 'Site already defined 2'; return; }

if ( !class_exists( "SportSite" ) ) {


if (!defined("SPORTSITE_CLASS")) {
	define("SPORTSITE_CLASS", 1);

//print 'Site included';

class SportSite {
	// get the site ID
	// NYC Sport News - 0
	// Chicago Sport News - 1
	// Big Apple Football News - 2
	// City Sports Media News - 3
	var $siteID;
	var $templateID;
	var $domain;
	var $title;
	var $shortTitle;
	var $isGlobal = false;
	var $showInHeader = false;   // determine whether site should be in header
    var $sortOrder;

	function &getAllSites() {
		$sites  = array(
		                  new SportSite(3,"citysportsnews.com",'citysportsmedia.com',"City Sports Media News ","nycforum/",true,false,"City Sports News"),
		                  new SportSite(3,"citysportsmedia.com",'citysportsmedia.com',"City Sports Media News ","nycforum/",true,true,"City Sports Media"),
                          new SportSite(3,"csm","citysportsmedia.com","City Sports Media News [Local] ","nycforum/",true,false,"City Sports News"),
                          new SportSite(3,"citysportsmedia.nycsportsnews.com","citysportsmedia.com","City Sports Media News","nycforum/",true,false,"City Sports News"),


                          new SportSite(0,"nycsportsnews.com",'nycsportsnews.com',"New York City Sporting News ","nycforum/",false,true, "NYC Sports News"),
                          new SportSite(0,"nyc.citysportsnews.com",'nycsportsnews.com',"New York City Sporting News ","nycforum/",false,false, "NYC Sports News"),
                          new SportSite(0,"nyc.citysportsmedia.com",'nycsportsnews.com',"New York City Sporting News ","nycforum/",false,false, "NYC Sports News"),
                          new SportSite(0,"nyc",'nycsportsnews.com',"New York City Sporting News [Local] ","nycforum/",false,false,"NYC Sports News" ),
                          new SportSite(0,"nyc2",'nycsportsnews.com',"New York City Sporting News [Local] ","nycforum/",false,false,"NYC Sports News"),

    					  new SportSite(1,"chicagosportingnews.com",'chicagosportingnews.com',"Chicago Sporting News ","chicagoforum/",false,true,"Chicago Sports"),
    					  new SportSite(1,"chicago.citysportsnews.com",'chicagosportingnews.com',"Chicago Sporting News ","chicagoforum/",false,false,"Chicago Sports"),
    					  new SportSite(1,"chicago.citysportsmedia.com",'chicagosportingnews.com',"Chicago Sporting News ","chicagoforum/",false,false,"Chicago Sports"),
    					  new SportSite(1,"chicago",'chicagosportingnews.com',"Chicago Sporting News [Local] ","chicagoforum/",false,false,"Chicago Sports"),
    					  new SportSite(1,"chicago2",'chicagosportingnews.com',"Chicago Sporting News [Local] ","chicagoforum/",false,false,"Chicago Sports"),

						  new SportSite(2,"bigapplefootball.org",'bigapplefootball.com',"Big Apple Football News ","bigappleforum/",false,true,"Big Apple Football"),
						  new SportSite(2,"bigapplefootball.citysportsnews.com",'bigapplefootball.com',"Big Apple Football News ","bigappleforum/",false,false,"Big Apple Football"),
						  new SportSite(2,"bigapplefootball.citysportsmedia.com",'bigapplefootball.com',"Big Apple Football News ","bigappleforum/",false,false,"Big Apple Football"),
                          new SportSite(0,"bigapple","bigapplefootball.com","Big Apple Football News [Local] ","bigappleforum/",false,false,"Big Apple Football"),
                          new SportSite(2,"bigapplefootball.nycsportsnews.com","bigapplefootball.com","Big Apple Football News ","bigappleforum/",false,false,"Big Apple Football"),


                          new SportSite(4,"texashsfootball.citysportsnews.com",'texasfootball.com',"Houston Sports News ","texasforum/",false,false,"Houston Sports"),
                          new SportSite(4,"houstonvarsity.citysportsmedia.com",'texasfootball.com',"Houston Sports News ","texasforum/",false,true,"Houston Sports"),
                          new SportSite(4,"HoustonVarsity.com",'texasfootball.com',"Houston Sports News ","texasforum/",false,false,"Houston Sports"),
                          new SportSite(0,"texas",'texasfootball.com',"Houston Sports News [LOCAL] ","texasforum/",false,false,"Houston Sports"),
                          new SportSite(0,"006506b.netsolhost.com","texasfootball.com","Houston Sports News ","texasforum/",false,false,"Houston Sports"),

                          new SportSite(5,"dc.citysportsnews.com",'dc.com',"DC News ","dcforum/",false,false,"DC Sports"),
                          new SportSite(5,"dc.citysportsmedia.com",'dc.com',"DC News ","dcforum/",false,false,"DC Sports"),
                          new SportSite(5,"dc",'dc.com',"DC News [LOCAL] ","dcforum/",false,false,"DC Sports")

    			   );
        return $sites;	}

	// get a list of all network sites
	// to display in the header drop-down
	function  &getSites() {
    	$dataset = array();
    	$sites =& SportSite::getAllSites();
    	$siteItem =  array ('siteUrl'=>'http://www.nycsportsnews.com','siteName'=>'(All network sites)');
    	$dataset[-1] = $siteItem;
    	foreach($sites as $site)
        {

    	    $siteUrl = 'http://'.$site->domain;
    	    $siteName = $site->shortTitle;
    	    $id = $site->siteID;
    	    $showInHeader =  $site->showInHeader;
    	    if ($showInHeader) {
    	    	$siteItem =  array ('siteUrl'=>$siteUrl,'siteName'=>$siteName);
    	    	$dataset[$id] = $siteItem;
         	}
    	}

 		$ds =& new ArrayDataSet($dataset);
        return $ds;
    }


     // create the Site definition
	 //parameters:
	 // siteID - ID of the site
	 // $domain - domain name
	 // $templatesFolder - folder for the site templates under the templates/source directory (if is not set - the domain name is used)
	 // $title  -  site title
	 // $forumURL  - relative url for the site forum
	 // $isGlobal - point that this site is global site (not implemented currently)
	function SportSite($siteID=0,$domain='',$templatesFolder='',$title='',$forumURL='forum',$isGlobal=false, $showInHeader = false, $showTitle='', $sortOrder=1)
	{
      $this->siteID = $siteID;
	  if(strlen(trim($templatesFolder)))
        $this->templatesFolder = $templatesFolder;
	  else
        $this->templatesFolder = $domain;
      $this->domain = $domain;
      $this->title=$title;
      $this->isGlobal = $isGlobal;
	  $this->forumURL = $forumURL;
	  $this->showInHeader = $showInHeader;
	  $this->shortTitle=$showTitle;
	  $this->sortOrder=$sortOrder;
	}

   function getSite()
   {      $sites =& SportSite::getAllSites();
      $host = strtolower(trim($_SERVER['HTTP_HOST']));
      if(!(strpos($host,':')===false))
          $host = substr($host,0,strpos($host,':'));
      foreach($sites as $site)
        {

    	   if ($host == $site->domain  || $host == 'www.'.$site->domain)
    	    {
    	    	return $site;
    	    }
    	}
       return null;
   }

    function getSiteID()
    {
    	$site = SportSite::getSite();
        if ($site!=null)
    	    {    	    	return $site->siteID;
    	    }
        return 0;
    }

	// Not Used
    function getTemplateSiteID()
    {
    	$site = SportSite::getSite();
        if ($site!=null)
    	    {
    	    	return $site->templateID;
    	    }
    }

    function IsGlobal()
    {
    	$site = SportSite::getSite();
        if ($site!=null)
    	{
    		return $site->isGlobal;
    	}
    	return false;
    }

	function getForumURL()
    {
    	$site = SportSite::getSite();
        if ($site!=null)
    	    {
    	    	return $site->forumURL;
    	    }
		return "forum/";
    }

    function getPublicTemplatePath($templateName)   ///only for /pub/  templates   - templateName - excluding /pub/
	{
	    $site = SportSite::getSite();
        if ($site!=null)
    	{
    	        $fullTemplatePath = "/".$site->templatesFolder."".$templateName;
    	       /* $lastSlashPos = strrpos($templateName,"/");
    	        if(!($lastSlashPos===false))
    	        {
    	            $templateDir  =  substr($templateName,0,$lastSlashPos);                    $templateFile =  substr($templateName,$lastSlashPos+1);
                    $fullTemplatePath    = $templateDir."/".$site->domain."/".$templateFile;    	        }                    */
    	    	return $fullTemplatePath;
    	}
    	else
    	 return $templateName;

	}

	function getSiteTemplateBase()
	{
	    $site = SportSite::getSite();
        if ($site!=null)
    	{
    	    	$path =  "/".$site->templatesFolder;
     	    	return  $path;
    	}
    	else
    	 return "";

	}

	function getSiteTemplateCSS()
	{
	    $site = SportSite::getSite();
        if ($site!=null)
    	{
    	    	$path =  "templates/source/".$site->templatesFolder."/style/style.css";
     	    	return  $path;
    	}
    	else
    	 return "style";

	}

    function getCity() {
    	return SportSite::getTitle();
    }

	function getTitle() {
	    $site = SportSite::getSite();
        if ($site!=null)
    	    {
    	    	return $site->title;
    	    }
    	return "N/A";
    }
}




}

}





?>